package com.zhangchenzhou.room.database;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import java.util.List;

import io.reactivex.Flowable;

/**
 * Created by 63453 on 2018/3/24.
 */
//dao 数据访问对象 data access object
@Dao
public interface UserDao {

    //查询操作的几种方式
    @Query("SELECT * FROM TableName_User")
    List<User> getAll();

    @Query("SELECT * FROM TableName_User")
    Flowable<List<User>> getAll1(); //

    @Query("SELECT * FROM TableName_User WHERE userId IN (:userIds)")
    List<User> loadAllByIds(int[] userIds);

    @Query("SELECT * FROM TableName_User WHERE user_name LIKE :first AND "
            + "sex LIKE :last LIMIT 1")
    User findByName(String first, int last);

    //插入操作的几种方式
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertUsers(User... users);
    @Insert
    void insertBothUsers(User user1, User user2);
    @Insert
    void insertUsersAndFriends(User user, List<User> friends);


    //删除和更新同插入操作的 方法参数一样  使用Delete注解
    @Delete
    void delete(User user);

    @Update
    void update(User user);

}
